// ALONEEFFECT

// World
float4x4 WorldViewProjection;
float4x4 World;

//Light
bool SolidBrown;
float3 LightPos;
float LightPower;
float Ambient;

Texture Texture;

sampler TextureSampler = sampler_state { texture = <Texture> ; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = mirror; AddressV = mirror;};
struct VertexToPixel
{
    float4 Position     : POSITION;    
    float2 TexCoords    : TEXCOORD0;
    float3 Normal        : TEXCOORD1;
    float3 Position3D    : TEXCOORD2;

};

struct PixelToFrame
{
    float4 Color        : COLOR0;
};


 VertexToPixel SimplestVertexShader( float4 inPos : POSITION0, float3 inNormal: NORMAL0, float2 inTexCoords : TEXCOORD0)

{
    VertexToPixel Output = (VertexToPixel)0;
    
    Output.Position =mul(inPos, WorldViewProjection);
    Output.TexCoords = inTexCoords;

    Output.Normal = normalize(mul(inNormal, (float3x3)World));    
    Output.Position3D = mul(inPos, World);

    return Output;
}


 float DotProduct(float3 lightPos, float3 pos3D, float3 normal)
 {
     float3 lightDir = normalize(pos3D - lightPos);
     return dot(-lightDir, normal);    
 }


PixelToFrame OurFirstPixelShader(VertexToPixel PSIn)
{
    PixelToFrame Output = (PixelToFrame)0;        

    float diffuseLightingFactor = DotProduct(LightPos, PSIn.Position3D, PSIn.Normal);
    diffuseLightingFactor = saturate(diffuseLightingFactor);
    diffuseLightingFactor *= LightPower;
    
    float4 baseColor = tex2D(TextureSampler, PSIn.TexCoords);
    if (SolidBrown == true)
        baseColor = float4(0.25f, 0.21f, 0.20f, 1);
    
    Output.Color = baseColor*(diffuseLightingFactor + Ambient);

    return Output;
}

technique Simplest
{
    pass Pass0
    {
         VertexShader = compile vs_2_0 SimplestVertexShader();
         PixelShader = compile ps_2_0 OurFirstPixelShader();
    }
}